﻿@using PagedList
@using PagedList.Mvc
@using CodeCamp.Models.EventMgmt
@model SiteUserSearchViewModel
@{
    var grid = new WebGrid(Model.SearchResults, canPage: false, canSort: true);
}

@if ((Model.SearchResults != null) && (Model.SearchResults.Count > 0))
{
    <div id="logPager1">
    @Html.PagedListPager(Model.SearchResults,
        page => Url.Action("SiteUsers", new RouteValueDictionary()
        {
            { "Page", page }
        }),
        PagedListRenderOptions.OnlyShowFivePagesAtATime)
    </div>

        @grid.GetHtml(
        tableStyle: "grid-table",
        headerStyle: "grid-head",
        alternatingRowStyle: "grid-alt-row",
        columns: grid.Columns
        (
            grid.Column(
                columnName: "",
                header: "",
                style: "ui-nowrap",
                format: @<text>@Html.ActionLink("Detail", "SiteUserDetail", new { id = @item.SiteUserId }) | 
                    @Html.ActionLink("Edit", "SiteUserEdit", new { id = @item.SiteUserId })</text>
            ),
            grid.Column("FirstName", "First Name"),
            grid.Column("LastName", "Last Name"),
            grid.Column(
                columnName: "EmailAddress",
                header: "Email",
                format: @<text>@item.EmailAddress</text>
                ),
            grid.Column(
                columnName: "PresenterId",
                header: "Presenter",
                format: @<text>@if (item.PresenterId == 0)
                               {
                    <text>&nbsp;</text>
                               }
                               else
                               {
                    <text>@Html.ActionLink("Presenter", "Details", "Presenters", new { id = @item.PresenterId, eventName = Model.EventShortName }, null)</text>
                               }
                </text>
            ),
            grid.Column(
                columnName: "",
                header: "Approved",
                format:
                @<text>
                    @if (item.IsApproved)
                    {
                        <text>yes</text>
                    }
                    else
                    {
                        <text>NO</text>
                    }
                </text>
            ),
            grid.Column(
                columnName: "",
                header: "Locked Out",
                format:
                @<text>
                    @if (item.IsLockedOut)
                    {
                        <text>YES</text>
                    }
                    else
                    {
                        <text>&nbsp;</text>
                    }
                </text>
            ),
            grid.Column("UserIdentityProvider", "Identity Provider"),
            grid.Column(
                columnName: "LastLoginUTC",
                header: "Last Login (UTC)",
                style: "datetime-nowrap",
                format: @<text>@item.LastLoginUTC</text>
                ),
            grid.Column(
                columnName: "LastOnlineActivityUTC",
                header: "Last Activity (UTC)",
                style: "datetime-nowrap",
                format: @<text>@item.LastOnlineActivityUTC</text>
                )
            )
        )
    
}


@using (Html.BeginForm("SiteUsers", "EventMgmt", FormMethod.Post))
{
    @Html.ValidationSummary(false)

    <fieldset>
        <legend>Site User Search</legend>

        <table style="text-align: left">
            <tr>
                <td class="editor-field">First&nbsp;Name:&nbsp;@Html.EditorFor(x => x.FirstName)</td>
                <td rowspan="5" style="vertical-align:bottom">
                    <input name="SearchButton" type="submit" value="Search" /><br />
                    <input name="ClearButton" type="submit" value="Clear" />
                </td>
            </tr>
            <tr>
                <td class="editor-field">Last&nbsp;Name:&nbsp;@Html.EditorFor(x => x.LastName)</td>
            </tr>
            <tr>
                <td class="editor-field">@Html.EditorFor(x => x.IsEventPresenter) Is Event Presenter</td>
            </tr>
            <tr>
                <td class="editor-field">Active Since: @Html.EditorFor(x => x.ActiveSince)</td>
            </tr>
            <tr>
                <td class="editor-field">Rows per page: @Html.EditorFor(x => x.RowsPerPage)</td>
            </tr>
        </table>

    </fieldset>    
}


    @Html.HiddenFor(model => model.UTCOffsetMinutes)

<script type="text/jscript" language="javascript">
    ourDate = new Date
    var uom = document.getElementById("UTCOffsetMinutes");
    if (uom != null) {
        uom.value = ourDate.getTimezoneOffset();
    }
</script>    
